<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:text name="title" /></title>
<link href="<%=request.getContextPath()%>/stage/css/inside.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath()%>/stage/js/jquery-1.4.2.min.js"></script>
<script type="text/JavaScript">
<!--
var formulaid;
$(document).ready(function() {
	$("#fdiv a").css('cursor','pointer');     //统一设置查询链接为手形
    $("#fdiv a").click(function(){         //点击查询条件，改变颜色
    	if($(this).css('color')=='yellow'){
    		$(this).css('color','#ccc');
    	}else{
    		$(this).css('color','yellow');
    	}      	
    	$("#reset").css('color','#ccc'); 
    })
})
function reset(){
	$("#fdiv a").css('color','#ccc');
	$("#wmin").val('');
	$("#wmax").val('');
}
function edit(id){
	var server ="<%=request.getContextPath()%>/editformula.action?formulaid="+id;
	$.post(server,null,callback,"json");
}
function callback(json){ 
	var obj = json.formula;
   	if(obj!=null){
   		formulaid=obj.formulaId;
   		$("#fdiv a").css('color','#ccc');
   		$("#myname").val(obj.formulaName);
   		$("#important").val(obj.importance);
   		$("#rate").val(obj.rate);
   		$("#state").val(obj.state);
   		var weiStr=obj.weight;
   		var bufStr=obj.buffing;
   		var coloStr=obj.colour;
   		var symStr=obj.symmetry;
   		var pureStr=obj.purity;
   		var fluoStr=obj.fluorescence;
   		var cutStr=obj.cutter;
   		var certStr=obj.cerificate;
		var arr
   		if(weiStr.length>0){
   	   		arr = weiStr.split("-");
   	   		$("#wmin").val(arr[0]);
   	   		$("#wmax").val(arr[1]);
   		}
   		if(bufStr.length>0){
   	   		arr = bufStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#buf a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(coloStr.length>0){
   	   		arr = coloStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#colo a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(symStr.length>0){
   	   		arr = symStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#sym a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(pureStr.length>0){
   	   		var arr = pureStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#pure a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(fluoStr.length>0){
   	   		var arr = fluoStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#fluo a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(cutStr.length>0){
   	   		var arr = cutStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#cut a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   		if(certStr.length>0){
   	   		var arr = certStr.split("|");
   	   		for(var i=0;i<arr.length;i++){
   	   			$.each($("#cert a"), function(name, value){
   	     			if($(this).html()==arr[i]){
   	     				$(this).css('color','yellow');
   	     			}
   	 			}); 
   	   	   	}
   		}
   	}else{
   	 	$("#mess").html('查询失败');//显示反馈信息  
   	}
}
function save(){
	if($("#myname").val().length<1||$("#rate").val().length<1){
		$("#mess").html('请输入公式名称和价格比例.');
		return false;
	}
	var weiStr="";
	var bufStr="";
	var coloStr="";
	var symStr="";
	var pureStr="";
	var fluoStr="";
	var cutStr="";
	var certStr="";
	if($("#wmin").val().length>0&&$("#wmax").val().length>0){
		weiStr=$("#wmin").val()+"-"+$("#wmax").val();
	}
 	$.each($("#buf a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		bufStr+=$(this).text()+"|";
    	}
	}); 
 	$.each($("#colo a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		coloStr+=$(this).text()+"|";
    	}
	}); 
	$.each($("#sym a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		symStr+=$(this).text()+"|";
    	}
	}); 
	$.each($("#pure a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		pureStr+=$(this).text()+"|";
    	}
	}); 
	$.each($("#fluo a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		fluoStr+=$(this).text()+"|";
    	}
	}); 
	$.each($("#cut a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		cutStr+=$(this).text()+"|";
    	}
	}); 
	$.each($("#cert a"), function(name, value){
    	if($(this).css('color')=='yellow'){
    		certStr+=$(this).text()+"|";
    	}
	});
	
	if(bufStr.length>0)bufStr=bufStr.substr(0,bufStr.length-1);
	if(coloStr.length>0)coloStr=coloStr.substr(0,coloStr.length-1);
	if(symStr.length>0)symStr=symStr.substr(0,symStr.length-1);
	if(pureStr.length>0)pureStr=pureStr.substr(0,pureStr.length-1);
	if(fluoStr.length>0)fluoStr=fluoStr.substr(0,fluoStr.length-1);
	if(cutStr.length>0)cutStr=cutStr.substr(0,cutStr.length-1);
	if(certStr.length>0){
		certStr=certStr.substr(0,certStr.length-1);
		certStr  = encodeURI(certStr);
		certStr = encodeURI(certStr);//注意要两次 
	}
	var server ="<%=request.getContextPath()%>/saveformula.action?";
	server+="formula.rate="+$("#rate").val()+"&formula.state="+$("#state").val()+"&formula.importance="+$("#important").val()
		+"&formula.weight="+weiStr+"&formula.colour="+coloStr+"&formula.purity="+pureStr+"&formula.cutter="+cutStr+"&formula.symmetry="+symStr
		+"&formula.buffing="+bufStr+"&formula.fluorescence="+fluoStr+"&formula.cerificate="+certStr;
	if(formulaid!=null)server+="&formula.formulaId="+formulaid;
	document.formulaform.action=server;
	return true;
}

function create(){
	var server ="<%=request.getContextPath()%>/toformula.action";
	window.location.href=server;
}
function dele(id){
	var r=confirm("确认是否删除该公式.");
	if (r==true){
		var server ="<%=request.getContextPath()%>/delformula.action?formulaid="+id;
		document.delform.action=server;
		document.delform.submit(); 
	}

}

//-->
</script>
</head>

<body
	onload="MM_preloadImages('<%=request.getContextPath()%>/stage/images/menu0_01.jpg','<%=request.getContextPath()%>/stage/images/menu0_02.jpg','<%=request.getContextPath()%>/stage/images/menu0_03.jpg','<%=request.getContextPath()%>/stage/images/menu0_04.jpg','<%=request.getContextPath()%>/stage/images/menu0_05.jpg','<%=request.getContextPath()%>/stage/images/menu0_06.jpg','<%=request.getContextPath()%>/stage/images/menu0_07.jpg')">
<div class="mainbody"><%@ include file="head1.jsp"%>
<div class="intermediate">
<h1>当前位置：首页&nbsp;&gt;&nbsp;<b><FONT COLOR="#FFCC66">公式管理</FONT></b></h1>
<%@ include file="left_user.jsp"%>
<div class="right">
<h4><img
	src="<%=request.getContextPath()%>/stage/images/jgkz/jgkz_03.jpg"
	width="187" height="17" /></h4>
<div class="jgkz_bt"><input type="image"
	src="<%=request.getContextPath()%>/stage/images/jgkz/jgkz_07.jpg"
	onclick="create()" /></div>
<div class="jgkz" id="fdiv">
<form name="formulaform" method="post" onsubmit="return save()">
<table width="98%" height="165" align="center" cellpadding="0"
	cellspacing="10">
	<tr>
		<td height="11%">名称：<input id="myname" name="formula.formulaName" type="text" class="sous1" maxlength="20"/></td>
		<td>优先级：
		 <select  id="important">   
           <option value="1">最重要</option>   
           <option value="2">第二级</option>   
           <option value="3">第三级</option>   
           <option value="4">第四级</option>   
           <option value="5">第五级</option>
           <option value="6">第六级</option>
           <option value="7">第七级</option>   
        </select> 
      </td>
	</tr>
	<tr>
	<tr>
		<td width="60%" height="11%" valign="baseline">重量： <label>
		<input maxlength="4" name="textfield" id="wmin" type="text" class="kuang1" onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"/> </label>-<label>
		<input maxlength="4" name="textfield" id="wmax" type="text" class="kuang1" onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"/> 克拉 </label></td>
		<td width="40%">抛光：<span class="zise1" id="buf"><a>Ideal</a>|<a>EX</a>|<a>VG</a>|<a>GD</a>|<a>Fair</a></span></td>
	</tr>
	<tr>
		<td height="11%">颜色：<span class="zise1" id="colo"><a>D</a>|<a>E</a>|<a>F</a>|<a>G</a>|<a>H</a>|<a>I</a>|<a>J</a>|<a>K</a>|<a>L</a>|<a>M</a>|<a>N</a></span></td>
		<td>对称：<span class="zise1" id="sym"><a>Ideal</a>|<a>EX</a>|<a>VG</a>|<a>GD</a>|<a>Fair</a></span></td>
	</tr>
	<tr>
		<td height="11%">净度：<span class="zise1" id="pure"><a>IF</a>|<a>VVS1</a>|<a>VVS2</a>|<a>VS1</a>|<a>VS2</a>|<a>SI1</a>|<a>SI2</a>|<a>SI3</a>|<a>P1</a>|<a>P2</a>|<a>P3</a></span></td>
		<td>荧光：<span class="zise1" id="fluo"><a>N</a>|<a>F</a>|<a>M</a>|<a>ST</a>|<a>VST</a></span></td>
	</tr>
	<tr>
		<td height="11%">切工：<span class="zise1" id="cut"><a>Ideal</a>|<a>EX</a>|<a>VG</a>|<a>GD</a>|<a>Fair</a></span></td>
		<td>价格比例：<input maxlength="4" name="textfield" id="rate" type="text" class="kuang2" value="1" onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))"/>
		&nbsp;&nbsp;公式种类：
		 <select  id="state">
		   <option value="2">零售公式</option>
		   <s:if test='!#session.USER_TYPE.equals("B")'>
           	<option value="3">特价公式</option>     
           </s:if>
        </select>
		</td>
	</tr>
	<tr>
		<td>证书：<span class="zise1" id="cert"><a>GIA</a>|<a>HRD</a>|<a>IGI</a>|<a>国检</a></span></td>
		<td><label> <input type="image" src="<%=request.getContextPath()%>/stage/images/common/submit1.gif"/>
		</label> <label> 
		<input type="image" onclick="reset()" id="reset" src="<%=request.getContextPath()%>/stage/images/common/reset1.gif" />
		</label></td>
	</tr>
	<tr><td colspan="2"><span style="color:yellow" id="mess"><s:property value="tips"/></span></td></tr>
</table>
</form>
</div>
<div class="jgkz_bt">价格公式列表：</div>
<div class="jgkz">
<form name="delform" method="post">
<table width="100%" border="0" align="center"
	cellpadding="0" cellspacing="0">
	<tr>
		<td height="30" align="center" class="xian_01">公式名称</td>
		<td height="30" align="center" class="xian_01">公式种类</td>
		<td height="30" align="center" class="xian_01">重 量</td>
		<td height="30" align="center" class="xian_01">颜 色</td>
		<td height="30" align="center" class="xian_01">净 度</td>
		<td height="30" align="center" class="xian_01">价格比例</td>
		<td height="30" align="center" class="xian_01">优先级</td>
		<td height="30" align="center" class="xian_01_1">操 作</td>
	</tr>
	<s:iterator value="dataList" status="u">
		<s:if test="#u.index%2!=0"><tr bgcolor="#2e2e2e"></s:if>
		<s:else><tr></s:else>
		<td width="12%" height="30" align="center" class="xian_02"><s:property value="formulaName"/></td>
		<td width="10%" height="30" align="center" class="xian_02">
			<s:if test="state==2">零售公式</s:if><s:else>特价公式</s:else>
		</td>
		<td width="12%" height="30" align="center" class="xian_02">&nbsp;<s:property value="weight"/></td>
		<td width="12%" height="30" align="center" class="xian_02">&nbsp;<s:property value="colour"/></td>
		<td width="10%" height="30" align="center" class="xian_02">&nbsp;<s:property value="purity"/></td>
		<td width="16%" height="30" align="center" class="xian_02">&nbsp;<s:property value="rate"/></td>
		<td width="10%" height="30" align="center" class="xian_02">&nbsp;<s:property value="importance"/></td>
		<td width="14%" height="30" align="center"><a href="javascript:edit(<s:property value="formulaId"/>)">修改</a>&nbsp;|&nbsp;<a href="javascript:dele(<s:property value="formulaId"/>)">删除</a></td>
	</tr>
	</s:iterator>
</table>
</form>
</div>
</div>
</div>
<%@ include file="foot.jsp"%></div>
</body>
</html>
